/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.img;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * <p>Project: app2022 - Img5
 * <p>Powered by webrx On 2022-01-21 10:03:18
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Img5 {
    public static void main(String[] args) throws IOException {
        var w = 500;
        var h = 500;
        var t = 2;
        var i = new BufferedImage(w, h, t);
        var g = i.createGraphics();
        //设置线条和文件的，抗锯齿（平滑）
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        g.setStroke(new BasicStroke(5));
        g.setColor(Color.GRAY);
        g.fillRect(0, 0, w, h);

        g.draw3DRect(15, 15, 100, 100, true);
        g.draw3DRect(135, 135, 100, 100, false);


        g.setColor(Color.BLUE);
        Polygon p = new Polygon();
        p.addPoint(50, 10);
        p.addPoint(90, 150);
        p.addPoint(20, 350);
        g.drawPolygon(p);

        //画圆 椭圆
        g.setColor(Color.pink);
        g.drawOval(300, 300, 50, 50);
        g.fillOval(200, 400, 100, 100);

        //扇形，圆弧
        //g.drawArc(250, 250, 100, 100, 0, 90);
        g.fillArc(250, 250, 100, 100, 0, 45);


        g.dispose();
        ImageIO.write(i, "png", new File("i.png"));
        Runtime.getRuntime().exec("cmd /k start i.png");
    }
}
